<template>
    <div class="template-index-Lu">
        <commpVxeTable
            :isCanWrap="true"
            :key="reCommpVxeTable"
            :config="dataTableConfig"
            :columns="columnsVxe"
            :formItem="formItem"
            @checkboxChange="checkboxChange"
            ref="administrativeOffice"
            @searchEvent="searchEvent"
            @resetEvent="resetEvent"
            >
             <template v-slot:operation_fsqr="{row}" data-desc="申请人">
                <span style="padding-right: 21;" v-if="row.fsqr.length == 2">
                    <span v-for="(trem,tI) in row.fsqr.split('')" :key="tI" >
                        {{trem}}
                        <span v-if="tI+1 !== row.fsqr.split('').length">&nbsp;&nbsp;</span>
                    </span>
                </span>
                <span style="padding-right: 21;" v-else>{{ row.fsqr }}</span>
            </template>
            <template v-slot:operation_btn="{row}" data-desc="自定操作栏">
                <a-form layout="inline">
                    <a-form-item>
                        <a-button class="green-btn" @click="reviseClick(row)" icon="eye">查看</a-button>
                    </a-form-item>
                    <a-form-item v-if="isTrun(row)">
                        <a-popconfirm
                            title="您确定要撤回这条申请吗?"
                            ok-text="确定"
                            cancel-text="取消"
                            @confirm="revoke(row)"
                            @cancel="cancel"
                            >
                            <a-button
                                icon="rollback"
                                class="red-btn">
                                撤回
                            </a-button>
                        </a-popconfirm>
                    </a-form-item>
                    <!-- <a-form-item v-if="isShow(row)">
                        <a-button class="blue-btn" @click="baoXiaoClick(row)" icon="money-collect">申请报销</a-button>
                    </a-form-item> -->
                    <a-form-item v-if="isShow(row)">
                        <a-button class="blue-btn" @click="reimbursementClick(row)" icon="money-collect">申请报销</a-button>
                    </a-form-item>
                    <a-form-item v-if="isSpecialMatter(row)">
                        <a-button class="blue-btn" @click="beforehandReimbursementClick(row)" icon="right">特殊事项申请</a-button>
                    </a-form-item>
                </a-form>
            </template>
        </commpVxeTable>
        <handleModal ref="handleModalRef" @resetEvent="resetEvent"></handleModal>
        <reimbursementModel ref="reimbursementModelRef" />
        <priorApplication ref="priorApplicationRef" />
    </div>
</template>
<script>
import  commpVxeTable   from '@/components/commp-vxe-table/commp-vxe-table.vue'
import handleModal from '../modal/handleModal.vue'
import reimbursementModel from './reimbursementModel'
import priorApplication from '../../internalControl/newApplyFor/reimbursement/priorApplication'
import {queryByJodId,queryAllYbJob,returnUpperzdyFlowJob,sqccbx} from './service/index'
import YchConstant from "@/api/YchConstant";
import store from '@/store'
export default {
    components: {
        commpVxeTable,
        handleModal,
        reimbursementModel,
        priorApplication
    },
    data() {
        return {
            reCommpVxeTable: '',
            url: {
                list:YchConstant.SPZX_OA + '/newflow-lgqs/flowJobPage',// 离岗请示-分页查询列表
                list_url: YchConstant.PREFIX_EFORM + '/manage/actAppHelp/list',
                delete_url: YchConstant.PREFIX_EFORM + '/manage/actAppHelp/delete',
                sync_url: YchConstant.PREFIX_EFORM + '/manage/actAppHelp/sync',
                uploadHelps_url: YchConstant.PREFIX_EFORM + '/manage/actAppHelp/upload',
            },
            dataTableConfig: {
                api: YchConstant.SPZX_OA + '/mydbyb/YbList',
                rowId: 'id',
                urlType: true,
                paramet: {}
            },
            columnsVxe: [
                {
                    title: '标题',
                    field: 'fbt',
                    // width: 100,
                    titleInterval:true,
                    slots: {
                        header:'data1_header',
                    }
                },{
                    title: '摘要',
                    field: 'fzy',
                    align:'left',
                    titleInterval:true,
                    slots: {
                        header:'data2_header',
                    }
                },{
                    title: '申请人',
                    field: 'fsqr',
                    width: 80,
                    interval:true,
                    slots: {
                        default:'operation_fsqr',
                    }
                },{
                    title: '申请时间',
                    field: 'fsqsj',
                    width: 150,
                },{
                    title: '环节名称',
                    field: 'fhjmc',
                },{
                    title: '操作',
                    field: 'jobid',
                    width: 250,
                    titleInterval:true,
                    slots: {
                    // 使用插槽模板渲染
                        header:'data3_header',
                        default: 'operation_btn',
                    },
                }
            ],
            formItem: [
                {
                    label: '申请人',
                    model: 'fsqr',
                },
                {
                    label: '流程名称',
                    model: 'flcmb',
                    type:'Select',
                    options:[{
                        label:'离岗请示',
                        value:'OA_LGQS'
                    },{
                        label:'请休假',
                        value:'OA_QXJ'
                    },{
                        label:'加班值班',
                        value:'OA_JBZB'
                    },{
                        label:'出差审批',
                        value:'NK_CCSP'
                    },{
                        label:'行政事务审批',
                        value:'OA_XZSWSP'
                    },{
                        label:'宣传信息审批',
                        value:'OA_XCXXSP'
                    },{
                        label:'会议室申请管理',
                        value:'OA_HYSSQGL'
                    },{
                        label:'办公用品申请',
                        value:'OA_BGYPSQ'
                    }]
                },
            ],
            idList: [],
            formData: {},
        }
    },
    methods: {
        // 勾选
        checkboxChange(val){
            //console.log('已选择111',val)
            this.idList = []
            if(val.length){
                val.forEach(item => {
                    this.idList.push(item.id)
                });
            }
        },
        // 搜索
        searchEvent(){
            this.dataTableConfig.paramet = {
                ...this.dataTableConfig.paramet,
            }
        },
        // 重置
        resetEvent(){
            this.dataTableConfig.paramet = {
                ...this.dataTableConfig.paramet,
            }
        },
        // 点击办理
        reviseClick(row){
            //console.log(row)
            let data = {
                jobId: row.jobid?row.jobid:'',
                lcmbbm: row.flcmb,
                fpid: row.fpid,
            }
            queryByJodId(data).then(res => {
                //console.log(res)
                let resA = res.result
                    resA.hjmc = '我的已办'
                if(res.code == 200){
                    this.$nextTick(_ => {
                        this.$refs.handleModalRef.modalClick(resA)
                    })
                }
            })
        },
        //
        isShow(row){
            let ids = store.getters.userInfo.id
            if(row.fuserid == ids && row.fsfkbx == '是'){
                return true
            } else {
                return false
            }
        },
        isSpecialMatter(row){
            let ids = store.getters.userInfo.id
            if(row.fuserid == ids && row.flcmb == 'NK_CCSP'){
                return true
            } else {
                return false
            }
        },
        // 报销
        baoXiaoClick(item){
            //console.log(item)
            let data = {
                ccid:item.fpid,
                sfkbx:'否'
            }
            sqccbx(data).then(res => {
                //console.log(res)
                if(res.code == 200){
                    this.$message.success(res.message)
                    this.reCommpVxeTable = Date.now()
                    this.$router.push({
                        path: '/internalControl/daiBan/index',
                    }).catch(err => {});
                } else {
                    this.$message.warning(res.message)
                }
            })
        },
        reimbursementClick(row){
            //console.log(row)
            this.$refs.reimbursementModelRef.visible = true
            this.$refs.reimbursementModelRef.getData({...row,view: false,heightType:'model'})
        },
        beforehandReimbursementClick(row){
            this.$refs.priorApplicationRef.visible = true
            this.$refs.priorApplicationRef.getData({...row})
        },
        isTrun(row){
            let ids = store.getters.userInfo.id
            if(row.fsfkch == '0' && row.fuserid == ids){
                return true
            }
        },
        // 撤回
        revoke(row){
            //console.log(row)
            //console.log(store.getters.userInfo.id)
            let data = {
                lcmbbm: row.flcmb,
                jobid: row.jobid
            }
            queryAllYbJob(data).then(res => {
                if(res.code == 200){
                    let rdata = {
                        lcmbbm: row.flcmb,
                        jobid: row.jobid,
                        opinion: '撤回申请',
                        shjid: res.result.result.result[0].id,
                        smgflag: "",
                        smsContent: ""
                    }
                    returnUpperzdyFlowJob(rdata).then(res => {
                        //console.log(res)
                        if(res.code == 200){
                            this.$message.success(res.message)
                            this.reCommpVxeTable = Date.now()
                        } else {
                            this.$message.warning(res.message)
                        }
                    })
                } else {
                    this.$message.warning(res.message)
                }
            })
        },
        cancel() {
            //console.log('Cancel');
        },
    },
}
</script>
